from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-21 14:03:12.092229
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 21, Nov, 2022
Time: 14:03:19
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.0101
Nobs: 847.000 HQIC: -51.3209
Log likelihood: 11089.6 FPE: 4.24413e-23
AIC: -51.5139 Det(Omega_mle): 3.81867e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299228 0.050447 5.931 0.000
L1.Burgenland 0.109745 0.034674 3.165 0.002
L1.Kärnten -0.106168 0.018472 -5.748 0.000
L1.Niederösterreich 0.210485 0.072489 2.904 0.004
L1.Oberösterreich 0.100830 0.068951 1.462 0.144
L1.Salzburg 0.251856 0.036762 6.851 0.000
L1.Steiermark 0.037255 0.048208 0.773 0.440
L1.Tirol 0.107545 0.039080 2.752 0.006
L1.Vorarlberg -0.060409 0.033689 -1.793 0.073
L1.Wien 0.053824 0.061590 0.874 0.382
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.068127 0.104039 0.655 0.513
L1.Burgenland -0.030238 0.071509 -0.423 0.672
L1.Kärnten 0.047680 0.038095 1.252 0.211
L1.Niederösterreich -0.173190 0.149495 -1.158 0.247
L1.Oberösterreich 0.378743 0.142199 2.663 0.008
L1.Salzburg 0.288753 0.075815 3.809 0.000
L1.Steiermark 0.108121 0.099421 1.088 0.277
L1.Tirol 0.316077 0.080595 3.922 0.000
L1.Vorarlberg 0.022541 0.069477 0.324 0.746
L1.Wien -0.020325 0.127018 -0.160 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197710 0.026120 7.569 0.000
L1.Burgenland 0.092536 0.017953 5.154 0.000
L1.Kärnten -0.008745 0.009564 -0.914 0.361
L1.Niederösterreich 0.268288 0.037532 7.148 0.000
L1.Oberösterreich 0.114756 0.035700 3.214 0.001
L1.Salzburg 0.052796 0.019034 2.774 0.006
L1.Steiermark 0.016833 0.024960 0.674 0.500
L1.Tirol 0.098591 0.020234 4.873 0.000
L1.Vorarlberg 0.055907 0.017443 3.205 0.001
L1.Wien 0.112346 0.031889 3.523 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104861 0.026782 3.915 0.000
L1.Burgenland 0.047237 0.018408 2.566 0.010
L1.Kärnten -0.017195 0.009806 -1.753 0.080
L1.Niederösterreich 0.197142 0.038484 5.123 0.000
L1.Oberösterreich 0.279539 0.036605 7.637 0.000
L1.Salzburg 0.120025 0.019517 6.150 0.000
L1.Steiermark 0.101604 0.025593 3.970 0.000
L1.Tirol 0.123455 0.020747 5.950 0.000
L1.Vorarlberg 0.069230 0.017885 3.871 0.000
L1.Wien -0.026623 0.032698 -0.814 0.416
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130284 0.048497 2.686 0.007
L1.Burgenland -0.049449 0.033333 -1.483 0.138
L1.Kärnten -0.039421 0.017758 -2.220 0.026
L1.Niederösterreich 0.167593 0.069686 2.405 0.016
L1.Oberösterreich 0.139717 0.066285 2.108 0.035
L1.Salzburg 0.285093 0.035341 8.067 0.000
L1.Steiermark 0.032329 0.046344 0.698 0.485
L1.Tirol 0.163106 0.037569 4.341 0.000
L1.Vorarlberg 0.103835 0.032386 3.206 0.001
L1.Wien 0.068564 0.059209 1.158 0.247
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058745 0.038405 1.530 0.126
L1.Burgenland 0.042487 0.026397 1.610 0.107
L1.Kärnten 0.049729 0.014062 3.536 0.000
L1.Niederösterreich 0.227197 0.055185 4.117 0.000
L1.Oberösterreich 0.272563 0.052492 5.192 0.000
L1.Salzburg 0.058063 0.027987 2.075 0.038
L1.Steiermark -0.006840 0.036701 -0.186 0.852
L1.Tirol 0.156257 0.029751 5.252 0.000
L1.Vorarlberg 0.068190 0.025647 2.659 0.008
L1.Wien 0.074154 0.046888 1.582 0.114
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185127 0.045972 4.027 0.000
L1.Burgenland -0.004487 0.031598 -0.142 0.887
L1.Kärnten -0.060912 0.016833 -3.619 0.000
L1.Niederösterreich -0.086494 0.066058 -1.309 0.190
L1.Oberösterreich 0.191633 0.062834 3.050 0.002
L1.Salzburg 0.059671 0.033501 1.781 0.075
L1.Steiermark 0.225818 0.043932 5.140 0.000
L1.Tirol 0.495009 0.035613 13.900 0.000
L1.Vorarlberg 0.047606 0.030700 1.551 0.121
L1.Wien -0.050974 0.056126 -0.908 0.364
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158584 0.052371 3.028 0.002
L1.Burgenland -0.009109 0.035996 -0.253 0.800
L1.Kärnten 0.064696 0.019176 3.374 0.001
L1.Niederösterreich 0.202604 0.075252 2.692 0.007
L1.Oberösterreich -0.067882 0.071579 -0.948 0.343
L1.Salzburg 0.222731 0.038164 5.836 0.000
L1.Steiermark 0.113818 0.050046 2.274 0.023
L1.Tirol 0.084217 0.040570 2.076 0.038
L1.Vorarlberg 0.121954 0.034973 3.487 0.000
L1.Wien 0.110136 0.063938 1.723 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356991 0.030877 11.562 0.000
L1.Burgenland 0.008748 0.021223 0.412 0.680
L1.Kärnten -0.024812 0.011306 -2.195 0.028
L1.Niederösterreich 0.227991 0.044368 5.139 0.000
L1.Oberösterreich 0.157777 0.042203 3.739 0.000
L1.Salzburg 0.053357 0.022501 2.371 0.018
L1.Steiermark -0.018157 0.029507 -0.615 0.538
L1.Tirol 0.117662 0.023920 4.919 0.000
L1.Vorarlberg 0.071541 0.020620 3.470 0.001
L1.Wien 0.050194 0.037697 1.331 0.183
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043860 0.161146 0.192613 0.165717 0.131893 0.124464 0.070051 0.231123
Kärnten 0.043860 1.000000 0.001933 0.131599 0.045163 0.099336 0.427801 -0.050843 0.101864
Niederösterreich 0.161146 0.001933 1.000000 0.345564 0.166509 0.311111 0.127848 0.192066 0.341062
Oberösterreich 0.192613 0.131599 0.345564 1.000000 0.235803 0.340568 0.178015 0.180529 0.275767
Salzburg 0.165717 0.045163 0.166509 0.235803 1.000000 0.153303 0.145228 0.152770 0.140445
Steiermark 0.131893 0.099336 0.311111 0.340568 0.153303 1.000000 0.163240 0.148550 0.092526
Tirol 0.124464 0.427801 0.127848 0.178015 0.145228 0.163240 1.000000 0.121970 0.164313
Vorarlberg 0.070051 -0.050843 0.192066 0.180529 0.152770 0.148550 0.121970 1.000000 0.019531
Wien 0.231123 0.101864 0.341062 0.275767 0.140445 0.092526 0.164313 0.019531 1.000000